/**
 * 清除字符串空格
 * @param {String} str 目标字符串
 * @param {String} pos 空格位置 ["both","left","right","all"]
 * @returns 清除空格后的字符串
 */
function trim(str, pos = "both") {
  if (pos == "both") {
    return str.replace(/^\s+|\s+$/g, "");
  } else if (pos == "left") {
    return str.replace(/^\s*/, "");
  } else if (pos == "right") {
    return str.replace(/(\s*$)/g, "");
  } else if (pos == "all") {
    return str.replace(/\s+/g, "");
  } else {
    return str;
  }
}

export default trim;
